function getAllCombin(array, n, sum, temp) {
  console.log(temp)
  // 当temp.length等于n的时候，函数开始产生返回值，退出调用栈
  if (temp.length === n) {
    if (temp.reduce((t, c) => t + c) === sum) {
      return temp;
    }
    return;
  }
  for (let i = 0; i < array.length; i++) {
    const current = array.shift();
    temp.push(current);
    const result = getAllCombin(array, n, sum, temp);
    if (result) {
      return result;
    }
    temp.pop();
    array.push(current);
  }
}
const arr = [1, 2, 3, 4, 5, 6];

console.log(getAllCombin(arr, 3, 10, []));
